package com.yanqu.road.timer;

import com.yanqu.road.queue.ClientLogMgr;

import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.executor.GeneralTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class DataAnalyticFlushTask extends GeneralTask {

    private Logger logger = LogManager.getLogger(DataAnalyticFlushTask.class.getName());

    private int lastFlushTime = DateHelper.getCurrentSecond();

    @Override
    public void doRun() {
        try {
            int gap = 30;

            if (DateHelper.getCurrentSecond() - lastFlushTime > gap) {
                ClientLogMgr.flush();
                lastFlushTime = DateHelper.getCurrentSecond();
            }
        }catch (Exception e){
            logger.error("DataAnalyticsMgr flush task error:", e);
        }
    }
}
